#include "LTextureFactory.h"



NS_CC_CORE_BEGIN


CCTexture2D* LTextureHelper::createTexture(int width , int height , ccColor4F color )
{
	CCRenderTexture* pRenderTexture  = CCRenderTexture::create( width , height , kCCTexture2DPixelFormat_RGBA8888 );

	pRenderTexture->beginWithClear( color.r , color.g , color.b , color.a );



	pRenderTexture->visit( );

	pRenderTexture->end( );

	CCImage* pImage = pRenderTexture->newCCImage( );

	CCTexture2D* pTexture = new CCTexture2D();

	pTexture->initWithImage( pImage );


	return pTexture;
}


CCSprite* LTextureHelper::createSprite( LTextureInfo* key )
{
	CCSprite* pSprite;

	if( strcmp( key->filePath , "" ) == 0 ){
		CCTexture2D* pTex = LTextureHelper::createTexture( key->width , key->height , key->color );
		pSprite = CCSprite::createWithTexture( pTex );
		pTex->release( );
	}
	else{
		pSprite = CCSprite::create( key->filePath ) ;
	}


	return pSprite;
}

CCSprite* LTextureHelper::createSpriteWithSpriteFrameName( LTextureInfo* key )
{
	CCSprite* pSprite;

	if( strcmp( key->filePath , "" ) == 0 ){
		CCTexture2D* pTex = LTextureHelper::createTexture( key->width , key->height , key->color );
		pSprite = CCSprite::createWithTexture( pTex );
		pTex->release( );
	}
	else{
		pSprite = CCSprite::createWithSpriteFrameName( key->filePath ) ;
	}


	return pSprite;
}


NS_CC_CORE_END